package com.example.sb211217javacv.opencv;

import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.Point;
import org.bytedeco.opencv.opencv_core.Scalar;
import org.bytedeco.opencv.opencv_core.Size;

import static org.bytedeco.opencv.global.opencv_imgcodecs.imread;
import static org.bytedeco.opencv.global.opencv_imgproc.*;

public class JavaCVTest {
    public static void smooth(String filename) {
        Mat image = imread("C:\\Users\\Administrator\\Desktop\\test.jpg");
        if (image != null) {
            System.out.println(String.format("宽::高 %s::%s", image.cols(), image.rows()));

            JavaCVUtil.imShow(image, "原图");


            circle(image, // 目标图像
                    new Point(420, 150), // 圆心坐标
                    65, // radius
                    new Scalar(0,200,0,0), // 颜色，绿色
                    2, // 线宽
                    8, // 8-connected line
                    0); // shift

            Scalar color = new Scalar(0, 0, 255, 0);
            int[] objects = new int[]{513, 1546, 641, 1638};
            for (int i = 0; i < objects.length; i = i + 4) {
                Point point = new Point(objects[i + 1], objects[i]);
                Point point1 = new Point(objects[i + 3], objects[i + 2]);
                rectangle(image, point, point1, color);
            }

            line(image, new Point(1395,1024), new Point(1495,1064), color);
            line(image, new Point(1495,1064), new Point(1882,1065), color);
            line(image, new Point(1882,1065), new Point(1879,971), color);
            line(image, new Point(1879,971), new Point(1395,1024), color);

            opencv_imgproc.putText(image, //目标图像
                    "Lake and Tower", // 文本内容(不可包含中文)
                    new Point(460, 200), // 文本起始位置坐标
                    FONT_HERSHEY_PLAIN, // 字体类型
                    2.0, // 字号大小
                    new Scalar(0,255,0,3), //文本颜色，绿色
                    1, // 文本字体线宽
                    8, // 线形.
                    false); //控制文本走向
            JavaCVUtil.imShow(image, "绘图");

            GaussianBlur(image, image, new Size(3, 3), 0);
//            imwrite("C:\\Users\\Administrator\\Desktop\\test1.jpg", image);
            JavaCVUtil.imShow(image, "平滑图");
        }
    }

    public static void main(String[] args) {
        smooth("001");
    }
}
